﻿namespace ValidationFramework
{
	/// <summary>
	/// Represents the configuration for a validation run.
	/// </summary>
	public class ValidationOptions
	{
		/// <summary>
		/// Get or Sets a RuleSet that rules must be a part of to pass the filter. If its an empty string all rules pass.
		/// </summary>
		public string RuleSet { get; set; }

		/// <summary>
		/// Indicates that an error should be thrown after a validation run if it contained any invalid items. 
		/// </summary>
		public bool ThrowExceptionOnError { get; set; }

		/// <summary>
		/// Indicates that an error should be thrown when the first invalid item is found - stopping all further processing of rules. 
		/// </summary>
		public bool ThrowExceptionOnFirstInvalidItem { get; set; }

		/// <summary>
		/// Indicates that an error should be thrown when testing member's with no rules
		/// </summary>
		/// <remarks>
		/// The default is false.
		/// </remarks>
		public bool ThrowOnNoRulesFound { get; set; }

		/// <summary>
		/// Gets a value indicating wether the supplied rule should be evaluated.
		/// </summary>
		/// <param name="rule"></param>
		/// <returns>true if the rule passes through the filter</returns>
		internal bool ShouldEvaluateRule(Rule rule)
		{
			// return yes if the ruleSet is empty or matches the supplied rule
			return string.IsNullOrEmpty(RuleSet) || rule.RuleSet == RuleSet;
		}
	}
}
